package models

import (
	"gorm.io/gorm"
	"types"
)

// 用户表
type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(30);not null;unique;comment:用户名称" json:"username"`
	Pwd      string `gorm:"type:char(32);not null;comment:用户密码" json:"pwd"`
	Phone    string `gorm:"type:char(11);not null;comment:用户手机号" json:"phone"`
	Salt     string `gorm:"type:varchar(30);not null;comment:盐" json:"salt"`
}

// 创建用户表
func (u *User) UserAdd() error {
	return types.Db.Create(&u).Error
}

// 用户查询
func (u *User) UserSever() (user *User, err error) {
	err = types.Db.Where("username = ?", u.Username).Find(&user).Error
	return
}
